home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Essentials / MacApp Documentation / MacApp.TECH$ Archives / 1991 / Feb 91 / MacApp.Tech$ 2⁄1⁄91 / 2834-TESetText()-Feb91 < prev    next >
Encoding:
Text File  |  1991-03-06  |  5.2 KB  |  165 lines  |  [TEXT/GEOL]

  1. Item    2530142                         1-Feb-91        05:34PST
  2.  
  3. From:   POWERUP.ENG                     Power Up Software,PRT
  4.  
  5. To:     MACAPP.TECH$                    MacApp Technical
  6.  
  7. ------------------------------------------------------------------------------
  8.  
  9. Sub:    TESetText()
  10.  
  11. Attn:   MacApp.Tech$
  12. SentBy: James Plamondon
  13. Subject:   TESetText()
  14. Gentlepersons,
  15.  
  16. I am having some trouble with a routine that uses TESetText().  For some
  17. inexplicable reason, it crashes somewhere in the bowels of _TextBox(), which I
  18. gather is called by TESetText().
  19.  
  20. The purpose of the routine is to determine the height of the given styled
  21. string in the given column width.
  22.  
  23. This one's got me stumped.  I'd appreciate any advice you can give me.  I know
  24. that you don't have much to go on.
  25.  
  26. Looking forward to discovering that I've made a really stupid (and easily
  27. corrected) mistake, I remain
  28.  
  29. Yours,
  30.  
  31. James Plamondon
  32.  
  33.  
  34.  
  35. {——————————————————————————————————————————————————————————————————————————————
  36. }
  37. {$ AUtil}
  38.  
  39. { TextHeightInCol():  This routine determines how tall a given string will
  40.   be, when displayed in a given style, with a given wordbreak routine, and
  41.   in a column of given width and infinite (well, maxint) height. }
  42. FUNCTION  TextHeightInCol(
  43.                        itsText:        Ptr;
  44.                        itsLength:      LONGINT;
  45.                        itsWidth:       INTEGER;
  46.                        itsTextStyle:   TextStyle;
  47.                        itsWordBreak:   ProcPtr)
  48.                        : INTEGER;
  49.    CONST
  50.        kMaxTEChars     = 32000;
  51.        kMinColWidth    = 20;
  52.  
  53.    VAR
  54.        result:         INTEGER;
  55.        theFontInfo:    FontInfo;
  56.  
  57.    BEGIN
  58.    {$IFC   qDebug}
  59.    FailNil(gZZZZZTE);                                          { Initialized
  60. in InitUProtoUtilities() }
  61.  
  62.    UseZZZZZTE(TRUE);
  63.    {$ENDC  qDebug}
  64.  
  65.    IF (itsLength = 0) | (itsWidth <= kMinColWidth) | (itsText = NIL)
  66.    THEN
  67.        result := 0
  68.    ELSE
  69.        BEGIN
  70.        GetTextStyleFontInfo(itsTextStyle, theFontInfo);
  71.  
  72.        IF (itsWidth < theFontInfo.widMax)
  73.        THEN
  74.            result := 0
  75.        ELSE
  76.            BEGIN
  77.            WITH gZZZZZTE^^ DO
  78.                BEGIN
  79.                SetRect(destRect, 0, 0, itsWidth, maxint);
  80.                SetRect(viewRect, 0, 0, itsWidth, maxint);
  81.  
  82.                inPort := thePort;                              { Current port
  83. }
  84.  
  85.                {$IFC qDebug}
  86.                Assertion((crOnly = 0), AtStr('(crOnly = 0)')); { if >=0, word
  87. wrap }
  88.                {$ENDC qDebug}
  89.  
  90.                wordBreak := gTEDefaultWordBreak;
  91.                END;  { with }
  92.  
  93.            IF itsWordBreak <> NIL
  94.            THEN
  95.                SetWordBreak(itsWordBreak, gZZZZZTE);           { set the word
  96. break routine }
  97.  
  98.  
  99. {————————————————————————————————————————————————————————————————
  100.                 NOTE!!! before writing your wordBreak routine, be sure to read
  101.                 Tech Note 267, "TextEdit Technicalities."
  102.  
  103. ————————————————————————————————————————————————————————————————}
  104.  
  105.            {$IFC   qDebug}
  106.            (*
  107.            writeln;
  108.            writeln('In TextHeightInCol(), about to call TESetText():');
  109.            write  ('                 itsText = ');
  110. WriteHexLongint(LONGINT(itsText)); writeln;
  111.            writeln('               itsLength = ', Min(itsLength,
  112. kMaxTEChars):1);
  113.            writeln('                itsWidth = ', itsWidth:1);
  114.            writeln('      theFontInfo.widMax = ', theFontInfo.widMax:1);
  115.            write  ('     gZZZZZTE^^.destRect = ');
  116. WriteRect(gZZZZZTE^^.destRect); writeln;
  117.            write  ('                gZZZZZTE = ');
  118. WriteHexLongint(LONGINT(gZZZZZTE)); writeln;
  119.            write  ('               gZZZZZTE^ = ');
  120. WriteHexLongint(LONGINT(gZZZZZTE^)); writeln;
  121.            write  ('            itsWordBreak = ');
  122. WriteHexLongint(LONGINT(itsWordBreak)); writeln;
  123.            write  ('    gZZZZZTE^^.wordBreak = ');
  124. WriteHexLongint(LONGINT(gZZZZZTE^^.wordBreak)); writeln;
  125.            *)
  126.            {$ENDC  qDebug}
  127.  
  128.       { The code dies in the bowels of the following call.  Why?  I haven't a
  129. clue! }
  130.            TESetText(itsText, Min(itsLength, kMaxTEChars), gZZZZZTE);
  131.  
  132.            { set the text style }
  133.            TESetSelect(0, maxint, gZZZZZTE);                   { select all of
  134. the text }
  135.            TESetStyle(doAll, itsTextStyle, kDontRedraw, gZZZZZTE); { set its
  136. style (!!! compatibility???) }
  137.            TECalText(gZZZZZTE);                                {
  138. ???necessary??? }
  139.  
  140.            result := TEGetHeight(
  141.                            gZZZZZTE^^.nLines,                  { end line }
  142.                            0,                                  { start line }
  143.                            gZZZZZTE);                          { the TEHandle
  144. }
  145.  
  146.            {$IFC qDebug}
  147.            (*
  148.            writeln;
  149.            writeln('In TextHeightInCol():');
  150.            writeln('                itsWidth = ',  itsWidth:5);
  151.            writeln('       gZZZZZTE^^.nLines = ',  gZZZZZTE^^.nLines:5);
  152.            writeln('                  result = ',  result:5);
  153.            *)
  154.            {$ENDC qDebug}
  155.            END;  { else }
  156.        END;  { else }
  157.  
  158.    TextHeightInCol := result;
  159.  
  160.    {$IFC   qDebug}
  161.    UseZZZZZTE(FALSE);
  162.    {$ENDC  qDebug}
  163.    END;  { TextHeightInCol }
  164.  
  165.